﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KATS_Client.UI
{
    public partial class QueueView : Form
    {
        public QueueView()
        {
            InitializeComponent();
            UpdateText();
        }

        /// <summary>The starting point of the displayed queue items</summary>
        int _Start = 0;
        public int Start
        {
            get { return _Start; }
            set
            {
                if (value < 0)
                {
                    _Start = 0;
                    return;
                }
                if (value > Client.FileActionsQueue.Count - 1)
                {
                    if (value > Start)
                    {
                        return;
                    }
                    Start = Client.FileActionsQueue.Count - 1;
                    return;
                }
                _Start = value;
            }
        }

        /// <summary>The number of queue items displayed</summary>
        static int _Length = 6;
        /// <summary>The number of queue items displayed</summary>
        public static int Length
        {
            get { return _Length; }
            set
            {
                if (_Length < 0)
                {
                    _Length = 1;
                    return;
                }
                _Length = value;
            }
        }

        /// <summary>
        /// The final item displayed
        /// </summary>
        public int End
        {
            get
            {
                int end = Start + Length;
                int max = Client.FileActionsQueue.Count;
                if (end > max)
                    end = max;
                return end;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Start -= Length;
            UpdateText();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Start += Length;
            UpdateText();
        }

        /// <summary>
        /// Update the text displayed in this form
        /// </summary>
        public void UpdateText()
        {
            this.label2.Text = Client.FileActionsQueue.GenerateQueueText(Start, Length);
            int count = Client.FileActionsQueue.Count;
            this.label1.Text = string.Format("{0} to {1} of {2}", _Start + 1, End, count);
        }

        private void QueueView_Load(object sender, EventArgs e)
        {

        }


    }
}
